#ifndef CONNECTIONHANDLER_H
#define CONNECTIONHANDLER_H

#include <QObject>
#include <QtWebKit/QWebPage>
#include <QUrl>
#include <QStringList>
#include <QMap>
#include <QtNetwork/QHttp>
#include <QtNetwork/QTcpSocket>
#include <QWebElement>
#include <QWebFrame>
#include <QDebug>

//TODO:
/*The connection handler should be only used for connecting to a web source -> put all parsing functions to the parser class!*/

class ConnectionHandler : public QObject
{
    Q_OBJECT
public:

    static ConnectionHandler* instance()
    {
        static ConnectionHandler* handler;
        qDebug()<<"INSTANCE";
        if(!handler)
        {
            qDebug()<<"CREATING INSTANCE";
            handler=new ConnectionHandler();
        }
        return handler;
    }

    void setUrl(const QString& host,const QString& path);   //using QHttp

    QHttp* getQHttp();
    //QWebPage getWebPage()const;

    void setPath(const QString& path);
    QString getPath()const;

signals:
    void finished(const QWebPage&);
    void setValue(const QString& stockSymbol, QMap<QString,qreal>& vals);

public slots:
    //void parse(bool);
    void started();
    void inProgress(int,int);
    void readyReadSlot(const QHttpResponseHeader& header);
    void connectionState(int state);

private:
    QHttp httpSocket;
    QTcpSocket socket;
    QString strPath;
    QWebPage page;

    explicit ConnectionHandler(QObject *parent = 0);


};

#endif // CONNECTIONHANDLER_H
